﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a video media object.
    /// </summary>
    [Serializable]
    public class Video : Element {
        private bool _autoplay;
        private bool _controls;
        private int? _height;
        private bool _loop;
        private bool _muted;
        private PreloadChoices? _preload;
        private string _poster;
        private string _src;
        private int? _width;

        /// <summary>
        /// Constructs an empty video element.
        /// </summary>
        public Video() { }

        /// <summary>
        /// Constructs a new Video element with the given source URL.
        /// </summary>
        /// <param name="src">The source URL of this video.</param>
        public Video(string src) {
            _src = src;
        }

        /// <summary>
        /// Determines whether or not to automatically play back this video.
        /// </summary>
        public bool AutoPlay {
            get { return _autoplay; }
            set { _autoplay = value; }
        }

        /// <summary>
        /// Determines whether or not to show controls with this video.
        /// </summary>
        public bool Controls {
            get { return _controls; }
            set { _controls = value; }
        }

        /// <summary>
        /// Determines the height in pixels of this video.
        /// </summary>
        public int? Height {
            get { return _height; }
            set { _height = value; }
        }

        /// <summary>
        /// Determines whether or not this video should be played in a loop.
        /// </summary>
        public bool Loop {
            get { return _loop; }
            set { _loop = value; }
        }

        /// <summary>
        /// Determines whether or not this video is muted by default.
        /// </summary>
        public bool Muted {
            get { return _muted; }
            set { _muted = value; }
        }

        /// <summary>
        /// Determes the URL of a resource to show while the video is loading.
        /// </summary>
        public string Poster {
            get { return _poster; }
            set { _poster = value; }
        }

        /// <summary>
        /// Determines how to preload content from this video.
        /// </summary>
        public PreloadChoices? Preload {
            get { return _preload; }
            set { _preload = value; }
        }

        /// <summary>
        /// Determines the URL of the source of this video.
        /// </summary>
        public string Src {
            get { return _src; }
            set { _src = value; }
        }

        /// <summary>
        /// Determines the width in pixels of this video.
        /// </summary>
        public int? Width {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _autoplay, "autoplay");
            AttributeWriter.Write(sb, _controls, "controls");
            AttributeWriter.Write(sb, _height, "height");
            AttributeWriter.Write(sb, _loop, "loop");
            AttributeWriter.Write(sb, _muted, "muted");
            AttributeWriter.Write(sb, _poster, "poster");
            AttributeWriter.Write(sb, _preload, "preload", true);
            AttributeWriter.Write(sb, _src, "src");
            AttributeWriter.Write(sb, _width, "width");
        }

    }
}
